package com.cn.yang.dao.impl;

import com.cn.yang.dao.MainPageDao;
import com.cn.yang.model.mainPage.HeadAndFootModel;
import com.cn.yang.model.mainPage.HeadLinkModel;
import com.cn.yang.model.mainPage.MainPageModel;
import com.cn.yang.util.GetSqlSession;
import com.cn.yang.util.JDBC;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class MainPageDaoImpl implements MainPageDao {
    JDBC jdbc = new JDBC();

    //头和尾的一些Model的查找和更新==============================
    @Override
    public HeadAndFootModel selectHeadFoot() {
        HeadAndFootModel model = GetSqlSession.getSqlSession().selectOne("com.cn.yang.dao.MainPageDao.selectHeadFoot");
        return model;
    }

    @Override
    public int updataHeadFoot(HeadAndFootModel model) {
        return GetSqlSession.getSqlSession().update("com.cn.yang.dao.MainPageDao.updataHeadFoot",model);
        // return 1;
    }
//headLINK的 查找更新=======================================
    @Override
    public List<HeadLinkModel> selectHeadLink() {
        return GetSqlSession.getSqlSession().selectList("com.cn.yang.dao.MainPageDao.selectHeadLink");
    }

    @Override
    public int addHeadLink(HeadLinkModel model) {
        return GetSqlSession.getSqlSession().insert("com.cn.yang.dao.MainPageDao.addHeadLink");
    }

    @Override
    public HeadLinkModel selectHeadLinkById(Integer id) {
        return GetSqlSession.getSqlSession().selectOne("com.cn.yang.dao.MainPageDao.selectHeadLinkById",id);
    }

    @Override
    public int updateById(HeadLinkModel model) {
        return GetSqlSession.getSqlSession().update("com.cn.yang.dao.MainPageDao.updateById",model);
    }

    @Override
    public int deleteHeadLink(String id) {
        return  GetSqlSession.getSqlSession().delete("com.cn.yang.dao.MainPageDao.deleteHeadLink",id);
    }
//中间首页的是否展示
    @Override
    public List<MainPageModel> findMainPage(MainPageModel model) {
        return GetSqlSession.getSqlSession().selectList("com.cn.yang.dao.MainPageDao.findMainPage",model);
    }
    public List<MainPageModel> findMainPage() {
        return GetSqlSession.getSqlSession().selectList("com.cn.yang.dao.MainPageDao.findAll");
    }
    @Override
    public int countMainPage() {
        return GetSqlSession.getSqlSession().selectOne("com.cn.yang.dao.MainPageDao.countMainPage");
    }

    @Override
    public MainPageModel selectById(Integer id) {
        return GetSqlSession.getSqlSession().selectOne("com.cn.yang.dao.MainPageDao.selectById",id);
    }

    @Override
    public int updateMainPage(MainPageModel model) {
        String sql = "update mainpage set title = '"+model.getTitle()+"',englishname ='"+model.getEnglishName()+"',isshow = '"+model.getIsshow()+"' where id = " +model.getId();
        int result = jdbc.update(sql);
        jdbc.closeConn();
        return result;
    }
}
